import { NextRequest } from "next/server"
import { withMiddleware } from "@/lib/middleware/entry"
import { prisma } from "@/lib/prisma"
import { MenuListParams } from "@/types/menu"

async function handler(req: NextRequest) {
  const params: MenuListParams = await req.json()
  const { sysCode } = params

  const menus = await prisma.menu.findMany({
    where: {
      sysCode,
      isActive: 1,
    },
    include: {
      categories: true,
    },
    orderBy: {
      order: "asc",
    },
  })

  return menus
}

export const POST = withMiddleware(handler)